.TH std::ptr_fun 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ptr_fun \- std::ptr_fun

.SH Synopsis
   Defined in header <functional>
   template< class Arg, class Result >
                                                         (deprecated in C++11)
   std::pointer_to_unary_function<Arg,Result>        \fB(1)\fP (removed in C++17)

       ptr_fun( Result (*f)(Arg) );
   template< class Arg1, class Arg2, class Result >
                                                         (deprecated in C++11)
   std::pointer_to_binary_function<Arg1,Arg2,Result> \fB(2)\fP (removed in C++17)

       ptr_fun( Result (*f)(Arg1, Arg2) );

   Creates a function wrapper object (either std::pointer_to_unary_function or
   std::pointer_to_binary_function), deducing the target type from the template
   arguments.

   1) Effectively calls std::pointer_to_unary_function<Arg,Result>(f).
   2) Effectively calls std::pointer_to_binary_function<Arg1,Arg2,Result>(f).

   This function and the related types are deprecated as of C++11 in favor of the more
   general std::function and std::ref, both of which create callable adaptor-compatible
   function objects from plain functions.

.SH Parameters

   f - pointer to a function to create a wrapper for

.SH Return value

   A function object wrapping f.

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example


// Run this code

 #include <algorithm>
 #include <functional>
 #include <iostream>
 #include <string_view>

 constexpr bool is_vowel(char c)
 {
     return std::string_view{"aeoiuAEIOU"}.find(c) != std::string_view::npos;
 }

 int main()
 {
     std::string_view s = "Hello, world!";
     std::ranges::copy_if(s, std::ostreambuf_iterator<char>(std::cout),
         std::not1(std::ptr_fun(is_vowel)));
 #if 0
 // C++11 alternatives:
         std::not1(std::cref(is_vowel)));
         std::not1(std::function<bool(char)>(is_vowel)));
         [](char c) { return !is_vowel(c); });
 // C++17 alternatives:
         std::not_fn(is_vowel));
 #endif
 }

.SH Output:

 Hll, wrld!

.SH See also

   function           wraps callable object of any copy constructible type with
   \fI(C++11)\fP            specified function call signature
                      \fI(class template)\fP
   move_only_function wraps callable object of any type with specified function call
   (C++23)            signature
                      \fI(class template)\fP
   invoke             invokes any Callable object with given arguments
   invoke_r           and possibility to specify return type
   \fI(C++17)\fP            (since C++23)
   (C++23)            \fI(function template)\fP
   not_fn             creates a function object that returns the complement of the
   \fI(C++17)\fP            result of the function object it holds
                      \fI(function template)\fP
